#include <cstdlib>  //include if not including any other standard libraries
    // include the standard libraries first here
    // then include other's non-standard libraries
    // then include the programs files

#include "Physical/property.h"


//
// Constructors/Destructors
//

/**
 * Empty Constructor
 */
physical::property::property ( )
{
    initAttributes();
}

/**
 * Other Constructors
 * Description of other what the constructor will do.
 * @param <parameter> <Description>
 */
physical::property::property ( double lattitude, double longitude )
{
    initAttributes();
    this->lattitude = lattitude;
    this->longitude = longitude;
}

/**
 * Empty Destructor
 */
virtual physical::property::~property ( )
{ }


//
// Methods
//
/**
 * Returns the location of the property
 * @param lattitude is the return of the lattitude of the property
 * @param longitude is the return of the longitude of the property
 * @return bool return true if successful, else false
 */
bool physical::property::getLocation ( double lattitude, double longitude )
{
    lattitude = getLattitude();
    longitude = getLongitude();
}

/**
 * Sets location of the station using lattitude and longitude. Returns TRUE if
 * successful, else FALSE.
 * @return bool
 * @param  lattitude Lattitude of station.
 * @param  longitude Longitude of station.
 */
bool physical::property::setLocation (double lattitude, double longitude )
{
    setLattitude(lattitude);
    setLongitude(longitude);
}

/**
 * Connects this property with another property. Returns TRUE if
 * successful, else FALSE.
 * @return bool
 * @param  otherProperty is a pointer to the other property.
 */
bool physical::property::connectProperty(property* otherProperty)
{
    if (propertyDeque.push_back(otherProperty))
    {
        setConnectionCount(getConnectionCount()+1);
        return true;
    }
    else
        return false;
}

/**
 * Disconnects this property from another property. Returns TRUE if
 * successful, else FALSE.
 * @return bool
 * @param  otherProperty is a pointer to the other property.
 */
bool physical::property::disconnectProperty(property* otherProperty)
{
    for (int i = 0; i < getConnectionCount(); i++)
    {
        property* propPtr = propertyDeque.at(i);
        if (propPtr == otherProperty)
        {
            propPtr = NULL;
            propertyDeque.erase(i);
            setConnectionCount(getConnectionCount()-1);
            return true;
        }
    }
    return false;
}

/**
 * Disconnects this property from all other properties. Returns TRUE if
 * successful, else FALSE.
 * @return bool
 * @param  otherProperty is a pointer to the other property.
 */
bool physical::property::disconnectAllProperty( )
{
    for (int i = 0; i < getConnectionCount(); i++)
    {
        property* propPtr = propertyDeque.at(i);
        propPtr = NULL;
        propertyDeque.erase(i);
        setConnectionCount(getConnectionCount()-1);
    }
    if (propertyDeque.empty())
    {
        setConnectionCount(0);
        return true;
    }
    else
        return false;
}

//
// Accessor methods
//

/**
 * Set the value of lattitude
 * Lattitude of the station.
 * @param new_var the new value of lattitude
 */
void physical::property::setLattitude ( double new_var )
{
    lattitude = new_var;
}

/**
 * Get the value of lattitude
 * Lattitude of the station.
 * @return the value of lattitude
 */
double physical::property::getLattitude ( )
{
    return lattitude;
}

/**
 * Set the value of longitude
 * Longitude of the station.
 * @param new_var the new value of longitude
 */
void physical::property::setLongitude ( double new_var )
{
    longitude = new_var;
}

/**
 * Get the value of longitude
 * Longitude of the station.
 * @return the value of longitude
 */
double physical::property::getLongitude ( )
{
    return longitude;
}

/**
 * Set the value of connectionCount
 * Count of properties this property is connected too.
 * @param new_var the new value of connectionCount
 */
void physical::property::setConnectionCount ( int new_var )
{
    connectionCount = new_var;
}

/**
 * Get the value of connectionCount
 * Count of properties this property is connected too.
 * @return the value of connectionCount
 */
int physical::property::getConnectionCount ( )
{
    return connectionCount;
}


//
// Other methods
//

/**
 * Initialization function of class variables.
 */
void physical::property::initAttributes ( )
{
    this->setLattitude(-1.0);
    this->setLongitude(-1.0);
}
